import Vue from 'vue'
import Vuex from 'vuex'
import Storage from "@/utils/storageUtils"

Vue.use(Vuex);

const store = new Vuex.Store({
  state: {
    token: Storage.Local.get("token") ? Storage.Local.get("token") : null,
    user: Storage.Local.get("user") ? Storage.Local.get("user") : null,
  },
  getters: {
    getToken(state) {
      return state.token;
    },
    getUser(state){
      return state.user;
    }
  },
  mutations: {
    setToken(state, val) {
      state.token = val;
      Storage.Local.set("token", val);
    },
    setUser(state, val) {
      state.user = val;
      Storage.Local.set("user", val);
    }
  }
});

export default store;

